<!DOCTYPE html>
<html>

<head>
    <title>游记列表</title>
    <meta charset="utf-8"/>
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
    <link rel="stylesheet" href="/js/bootstrap/css/bootstrap.min.css">
    <script src="/js/jquery/jquery.min.js"></script>
    <script src="/js/bootstrap/js/bootstrap.min.js"></script>
    <link rel="stylesheet" href="/css/font/css/font-awesome.min.css">
    <link rel="stylesheet" href="/css/reset.css"/>
    <link rel="stylesheet" href="/css/travel.css"/>
    <script src="/js/plugins/jrender/jrender.min.js"></script>
    <link rel="stylesheet" href="/js/plugins/dialog2/dialog.css">
    <script src="/js/plugins/dialog2/dialog.min.js"></script>
    <link rel="stylesheet" href="/css/comment.css">


<script>
    $(function () {


        //查询周推荐
            $.get('/travels/commends',{type:1,pageSize:3},function (data) {
                $('#travelsCommends').renderValues(data,{
                    setHref:function (item,value) {
                        var href = $(item).data("href"); //得到href
                        $(item).attr("href",href + value);//手动拼接跳转的url
                    }

                });
            $('#loopPlay:first').addClass("active")
        })





     //从共享数据中得到当前用户的id
        var user = JSON.parse(sessionStorage.getItem("user"));


        //分页查询需要拼接的临时变量
        var currentPage = 1;
        //解决上一1页时数据丢失的问题
        var dataList = [];
        //总页数变量
        var totalPage = 1;
        //方法的抽取
        function query() {
            //第一页的数据
            //发送异步请求获取用户游记列表
            $.get("/travels",{currentPage:currentPage} ,function (data) {

                //每一次查询完将数据保存到数组中,并且合并数据
                dataList = $.merge(dataList, data.list);
                console.log(dataList);
                console.log(dataList[0].greatCount.count);
                //渲染数据,要符合jrender的格式
                $("#allTravels").renderValues({list: dataList}, {
                    //value就是render-value渲染的值
                    setHref: function (item, value) {
                        var href = $(item).data("href"); //得到href
                        $(item).attr("href", href + value);//手动拼接跳转的url
                    },
                    setUserId:function (item, value) {
                        var href = $(item).data("href"); //得到href
                        $(item).attr("href", href + value);//手动拼接跳转的url
                    }
                });

                $.each(dataList,function (index, item) {


                })
                //第一页数据,,,每次查询完之后页面加一
                currentPage += 1;
                //将第一查询的总页数封装成变量
                totalPage = data.pages;
            })
        }
        //第一次查询
        query();


        //屏幕滚动事件
        $(window).scroll(function () {
            //触发翻页的ajax去查询
            //触发翻页的时机.  屏幕高度+滚动高度>=数据的高度的时候
            if ($(window).height()+$(document).scrollTop()>=$(document).height()) {
                //解决翻页底部问题,一直发送请求,如果当前页小于总页数的时候
                if (currentPage <= totalPage) {
                    query();
                } else {
                    //已经到最后一页
                    $(document).dialog({
                        type: "notice",
                        infoText: "到底了........",
                        autoClose: 1000,
                        position: "bottom" //在底部显示
                    })
                }
            }
        })

    })
</script>
</head>

<body>


<div class="search-head">
    <div class="row nav-search">
        <div class="col-2">
            <a href="index.html">
                <span><i class="fa fa-chevron-left fa-2x"></i></span>
            </a>
        </div>
        <div class="col-10">
            <div class="input-group-sm search">
                <input class="form-control searchBtn" placeholder="搜游记">
            </div>
        </div>
    </div>
</div>


<div class="container" style="width: 100%">

    <h6>每月冠军游记</h6>
    <div id="carouselExampleControls" class="carousel slide" data-ride="carousel" >
        <div id="travelsCommends" class="carousel-inner">
            <div render-loop="list">
                <div class="carousel-item" id="loopPlay">
                    <div class="border commend">
                        <a data-href="travelContent.html?id=" render-fun="setHref" render-key="list.r_id">
                            <img render-src="list.coverUrl" width="100%" height="200px">
                            <h1 render-html="list.title"></h1>
                            <small render-html="list.subTitle"></small>
                        </a>
                    </div>
                </div>
            </div>
        </div>

        <a class="carousel-control-prev" href="#carouselExampleControls" role="button" data-slide="prev">
            <span class="carousel-control-prev-icon" aria-hidden="true"></span>
            <span class="sr-only"></span>
        </a>
        <a class="carousel-control-next" href="#carouselExampleControls" role="button" data-slide="next">
            <span class="carousel-control-next-icon" aria-hidden="true"></span>
            <span class="sr-only"></span>
        </a>
    </div>
</div>

<div class="container" style="width: 100%">
    <h6>全部游记</h6>
    <div id="allTravels">
        <div  render-loop="list">
            <div class="row detail">
                <div class="col">
                    <a href="travelContent.html?id=" render-fun="setHref" render-key="list.id">
                        <h4 render-html="list.title"></h4>
                    </a>
                    <!--团队开发时做-->
                    <p>
                        <a data-href="/friend/profiles.html?id=" render-fun="setHref" render-key="list.author.id">
                        <a data-href="/friend/profiles.html?id=" render-fun="setUserId" render-key="list.author.id">
                            <img class="rounded-circle head-img" render-src="list.author.headImgUrl">
                            <span render-html="list.author.nickName"></span> </a> 在
                        <span class="addr" render-html="list.place.name" ></span>
                        </a>
                    </p>
                    <p>
                        <i class="like" id="likeBtn">&#10084;</i>
                        <span render-html="">2</span>
                        <i class="fa fa-commenting fa-fw"></i>
                        <span>0</span>
                    </p>
                </div>
                <div class="col bigimg">
                    <a data-href="travelContent.html?id=" render-fun="setHref" render-key="list.id">
                        <img  render-src="list.coverUrl">
                    </a>
                </div>
            </div>
        </div>
    </div>
</div>


</body>

</html>